{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import os\n",
    "import numpy as np\n",
    "filepath = 'Electricity Consumption/'\n",
    "dirs = os.listdir(filepath)\n",
    "dirs.sort()\n",
    "dirs = dirs[1:]\n",
    "\n",
    "STA = pd.DataFrame(index = dirs, columns = ['Mean','Standard deviation','Skew','Kurtosis',\\\n",
    "'0th percentile','2.5th percentile','50th percentile','97.5th percentile','100th percentile'],dtype = 'float')\n",
    "\n",
    "for file in dirs:#A\n",
    "    data = pd.DataFrame()\n",
    "    # print(file)\n",
    "    if not os.path.isdir(filepath+file):  \n",
    "        f = open(filepath+file)\n",
    "        s = [] \n",
    "        print(s.append(f))\n",
    "    else:\n",
    "        path1 = filepath+file\n",
    "        files1 = os.listdir(path1)#A01\n",
    "        for file1 in files1:\n",
    "            if not os.path.isdir(path1+'/'+file1):   \n",
    "                f = open(path1+'/'+file1)\n",
    "                s = [] \n",
    "                print(s.append(f))\n",
    "            else:\n",
    "                path2 = path1+'/'+file1\n",
    "                files2 = os.listdir(path2)#file\n",
    "                for file2 in files2:\n",
    "                    if (file2 !='.DS_Store' )&(file2!='.ipynb_checkpoints'):\n",
    "                        # print(file2)\n",
    "                        d = pd.read_csv(path2+\"/\"+file2)\n",
    "\n",
    "                        d.insert(0,'file',file2[:-4])\n",
    "                        data = data.append(d)\n",
    "    data.to_csv('process result/EC_'+str(file)+'.csv')\n",
    "    ##statistics\n",
    "    STA.loc[file,'Mean'] = data['Value'].mean(axis=0)\n",
    "    STA.loc[file,'Standard deviation'] = data['Value'].std(axis=0)\n",
    "    STA.loc[file,'Skew'] = data['Value'].skew(axis=0)\n",
    "    STA.loc[file,'Kurtosis'] = data['Value'].kurtosis(axis=0)\n",
    "    STA.loc[file,'0th percentile'] = data['Value'].quantile(q=0)\n",
    "    STA.loc[file,'2.5th percentile'] = data['Value'].quantile(q=0.025)\n",
    "    STA.loc[file,'50th percentile'] = data['Value'].quantile(q=0.5)\n",
    "    STA.loc[file,'97.5th percentile'] = data['Value'].quantile(q=0.975)\n",
    "    STA.loc[file,'100th percentile'] = data['Value'].quantile(q=1)#np.round(,2)\n",
    "    STA = STA.round(2)\n",
    "STA.to_csv('process result/isic_statistic_info.csv',float_format='%.2f')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
